package com.alliky.core.base

import android.os.Bundle
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.alibaba.android.arouter.launcher.ARouter
import com.alliky.core.utils.RxToast
import com.alliky.core.R
import com.alliky.core.widget.LoadingDialog
import com.gyf.immersionbar.ImmersionBar
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity

/**
 * ================================================
 * @Description: 描述
 * @Author: wxianing
 * @Date: 2022/11/3 17:57
 * ================================================
 */
abstract class BaseActivity<T : ViewDataBinding> : RxAppCompatActivity() {

    private lateinit var mLoadingDialog: LoadingDialog

    var mBinding: T? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ARouter.getInstance().inject(this)
        mLoadingDialog = LoadingDialog(this, false)
        mBinding = DataBindingUtil.setContentView(this, getLayoutId())

        ImmersionBar.with(this).statusBarColor(R.color.deepskyblue).fitsSystemWindows(true)
            .statusBarDarkFont(false).init()

        initData(savedInstanceState)
        initObservable()
    }

    abstract fun getLayoutId(): Int
    abstract fun initData(savedInstanceState: Bundle?)
    abstract fun initObservable()

    fun showLoading() {
        mLoadingDialog.showDialog(this, false);
    }

    fun hideLoading() {
        mLoadingDialog.dismissDialog()
    }

    override fun onDestroy() {
        super.onDestroy()
        mBinding?.unbind()
    }

    fun showMessage(message: String) {
        RxToast.normal(message)
    }
}